<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title>我的账单</title>
		<link rel="stylesheet" href="css/muse-ui.css">
		<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,400italic">
		<link rel="stylesheet" href="https://cdn.bootcss.com/material-design-icons/3.0.1/iconfont/material-icons.css">
		<link rel="stylesheet" href="css/muse-ui-loading.css">
		<link rel="stylesheet" href="https://at.alicdn.com/t/font_951857_sr7zod4vu4.css">
		<script src="js/vue.min.js"></script>
		<script src="js/muse-ui.js"></script>
		<script src="js/muse-ui-loading.js"></script>
		<script src="js/muse-ui-toast.js"></script>
		<script src="js/axios.min.js"></script>
		<script src="js/mui.min.js"></script>
		<script src="js/utils.js"></script>
		<style>
			.container{
				height:calc(100vh);
				width: 100%;
			}
			.container input {
				color: #ff4081;
			}
			.login-head{
				margin-top: 20%;
				width: 100%;
				text-align: center;
			}
			.icon-denglu{
				color: #fff;
				font-size: 70px;
			}
			.item{
				display: flex;
			}
		</style>
	</head>
	<body>
		<div id="body">
			<mu-appbar color="secondary" style="width: 100%;position: fixed;top: 0;padding-top: 20px;height: auto;">
				<mu-button icon slot="left" @click="util.back()">
					<mu-icon value="arrow_back"></mu-icon>
				</mu-button>
				余额明细
			</mu-appbar>
			<mu-button large fab color="red" style="position: fixed;z-index: 9999;bottom: 15px;left: 45%;" @click="recharge">
				充
			</mu-button>
			<div style="width: 100%;position: fixed;top: 76px;display: flex;justify-content: center;align-items: center;height: 50px;background-color: #3FCCF0;color: #FFFFFF;font-size: 18px;font-weight: bold;">余额:{{owner.money}}元</div>
			<mu-container ref="container" style="padding-top: 120px;">
				<mu-load-more @refresh="refresh" :refreshing="refreshing" :loading="loading" @load="load">
					<mu-list>
						<template v-for="(item,index) in list">
							<div style="padding: 15px;display: flex;justify-content: space-between;">
								<span>{{item.remask}}</span>
								<span v-if="item.type==0" style="color: green;">+{{item.money}}元</span>
								<span v-else style="color: red;">-{{item.money}}元</span>
							</div>
							<mu-divider />
						</template>
					</mu-list>
				</mu-load-more>
			</mu-container>
		</div>
	</body>
	<script type="text/javascript">
		var vm = new Vue({
			el: "#body",
			data() {
				return {
					list: [],
					limit: 20,
					tabindex: 0,
					refreshing: false,
					loading: false,
					num: 20,
					owner:{money:0}
				}
			},
			methods: {
				getOwnerByUserId(){
					util.ajax("/api/method/getOwnerByUserId", null, data => {
						this.owner = data.object[0];
					})
				},
				isNumber(value) {
					var patrn = /^(-)?\d+(\.\d+)?$/;
					if (patrn.exec(value) == null || value == "") {
						return false
					} else {
						return true
					}
				},
				recharge() {
					var money = window.prompt("请输入充值金额", "充值");
					if (!this.isNumber(money)){
						util.tip("请输入正确的充值金额!")
						return;
					}
					if(money<=0){
						util.tip("充值金额必须大于0元!")
						return;
					}
				},
				refresh() {
					this.refreshing = true;
					this.$refs.container.scrollTop = 0;
					var params = {
						start: 1,
						limit: this.limit,
						payState: this.tabindex == 0 ? '未支付' : '已支付'
					}
					util.ajax("/api/method/getMoneyDetails", params, data => {
						this.refreshing = false;
						this.list = data.object.list;
					})
				},
				load() {
					this.loading = true;
					var params = {
						start: this.list.length + 1,
						limit: this.limit,
						payState: this.tabindex == 0 ? '未支付' : '已支付'
					}
					util.ajax("/api/method/getMoneyDetails", params, data => {
						this.loading = false;
						this.list = this.list.concat(data.object.list);
					})
				},
			}
		})
		document.addEventListener('plusready', function() {
			vm.refresh();
			vm.getOwnerByUserId()
			plus.webview.currentWebview().addEventListener("show", () => {
				vm.refresh();
				vm.getOwnerByUserId()
			}, null);
		});
	</script>
</html>
